<?php 

require_once("../models/config.php");
require_once("../ui.php");
require_once("../stats/db.php");
include_once("bar.graph.php");

if(!isUserLoggedIn()) {
	header ("location: login.php");
	die();
}

global $loggedInUser;
global $db;

$sql = "SELECT `Id` AS Id, `Name` AS Name FROM `debugging_Tool_Categories` ORDER BY `Name`";

$result = $db->sql_query($sql);
if (!$result) {
	$error = $db->sql_error();
	return;
}

$categories = array();
$names = array();
$rows = $db->sql_fetchall();
foreach($rows as $i => $row) {
	$categories[] = $row['Id'];
	$names[] = $row['Name'];
}

$categoryUsages = array();
foreach($categories as $i => $categoryId) {
	$categoryUsages[] = getToolUsagesForCategory($categoryId);
}

echo "<p>";	
echo "<img src='tools.general.usage.graph.php?userId=$loggedInUser->user_id'></img>";
echo "</p>";

foreach($categories as $i => $categoryId) {
	echo "<p>";	
	echo "Category '$names[$i]' was used during $categoryUsages[$i] debugging sessions.<br>";  
	
	echo "<img src='tools.usefulness.graph.php?userId=$loggedInUser->user_id&categoryId=$categoryId' " .
		"height='" . GRAPH_HEIGHT . " width=' " . GRAPH_WIDTH . "'></img>";
	echo "</p>";
}
	
?>